<template>
  <div class="app-container">
    <el-form ref="form" :model="queryParams" label-width="80px">
        <el-select v-model="queryParams.status" placeholder="请选择出租状态">
          <el-option label="待租" value="0"></el-option>
          <el-option label="已出租" value="1"></el-option>
          <el-option label="装修" value="2"></el-option>
        </el-select>
        <el-select v-model="queryParams.publishStatus" placeholder="请选择发布状态">
          <el-option label="已发布" value="0"></el-option>
          <el-option label="未发布" value="1"></el-option>
        </el-select>
        <el-input style="width: 15%" v-model="queryParams.premisesName" placeholder="请输入楼盘关键字"></el-input>
        <el-input style="width: 15%" v-model="queryParams.roomName" placeholder="请输入房源名称关键字"></el-input>
      <el-button @click="submitForm">查询</el-button>
    </el-form>
    <el-button type="primary" @click="recommend">推荐房源</el-button>
    <el-button type="primary" @click="cancelRecommend">取消推荐</el-button>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="id" align="center" prop="id"/>
      <el-table-column label="房源图片" align="center">
        <template slot-scope="scope">
          <img :src="scope.row.frontCover" width="80px" height="80px">
        </template>
      </el-table-column>
      <el-table-column label="房源名称" align="center" prop="roomName"/>
      <el-table-column label="楼盘名称" align="center" prop="premisesName"/>
      <el-table-column label="房源编号" align="center" prop="roomCode"/>
      <el-table-column label="面积" align="center" prop="proportion"/>
      <el-table-column label="租金" align="center" prop="rental">
        <template slot-scope="scope">
          <span v-html="scope.row.rental+'元/月'"></span>
        </template>
      </el-table-column>
      <el-table-column label="出租状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">待租</span>
          <span v-if="scope.row.status==1">已出租</span>
          <span v-if="scope.row.status==2">装修</span>
        </template>
      </el-table-column>
      <el-table-column label="发布人" align="center" prop="userName"/>
      <el-table-column label="发布状态" align="center" prop="floor">
        <template slot-scope="scope">
          <span v-if="scope.row.publishStatus==0">已发布</span>
          <span v-if="scope.row.publishStatus==1">未发布</span>
        </template>
      </el-table-column>
      <el-table-column label="是否推荐" align="center" prop="recommended">
        <template slot-scope="scope">
          <span v-if="scope.row.recommended==1">已推荐</span>
          <span v-if="scope.row.recommended==2">未推荐</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import {listInfo, getInfo, delInfo, addInfo, updateInfo, recommend, cancelRecommend} from "@/api/house/room";

  export default {
    name: "Info",
    components: {},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 状态
        status: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          houseId: null,
          frontCover: null,
          roomName: null,
          roomCode: null,
          proportion: null,
          direction: null,
          rental: null,
          decorateStyle: null,
          buildingName: null,
          floor: null,
          floorCount: null,
          status: null,
          publishStatus: null,
          premisesName: null,
          privateFacility: null,
          recommended: null,
          reserve1: null,
          reserve2: null,
          reserve3: null,
          reserve4: null,
          reserve5: null,
          deptId: null,
          styleId: null,
          finishDate: null,
          vacancyDate: null,
          delFlg: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          delFlg: [
            {required: true, message: "删除标识。0:未删除，1：删除不能为空", trigger: "blur"}
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /**推荐房源**/
      recommend() {
        if(this.ids.length==0){
          alert("请选择要推荐的房源");
        }else if(this.ids.length>1){
          alert("只能选择一个")
        }else if(this.status==1){
          alert("推荐房源不可再次推荐")
        }else {
          recommend(this.ids).then(res=>{
            if(res.code==200){
              this.$message.success("推荐成功");
              this.getList();
            }
          })
        }
      },
      /**取消推荐**/
      cancelRecommend() {
        if(this.ids.length==0){
          alert("请选择要推荐的房源");
        }else if(this.ids.length>1){
          alert("只能选择一个")
        }else if(this.status==2){
          alert("取消推荐房源不可再次取消")
        }else {
          cancelRecommend(this.ids).then(res=>{
            if(res.code==200){
              this.$message.success("取消推荐成功");
              this.getList();
            }
          })
        }
      },
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          houseId: null,
          frontCover: null,
          roomName: null,
          roomCode: null,
          proportion: null,
          direction: null,
          rental: null,
          decorateStyle: null,
          buildingName: null,
          floor: null,
          floorCount: null,
          status: 0,
          privateFacility: null,
          recommended: null,
          reserve1: null,
          reserve2: null,
          reserve3: null,
          reserve4: null,
          reserve5: null,
          deptId: null,
          createTime: null,
          styleId: null,
          finishDate: null,
          vacancyDate: null,
          delFlg: null,
          updateTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.status = selection.map(item => item.recommended)
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改【请填写功能名称】";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.getList();
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/info/export', {
          ...this.queryParams
        }, `system_info.xlsx`)
      }
    }
  };
</script>
